package com.thysdy.flowable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.thysdy.flowable.entity.ProcessassignConfig;
import com.thysdy.flowable.entity.RequestVo;
import com.thysdy.flowable.enums.CodeEnum;
import com.thysdy.flowable.exception.MyException;
import com.thysdy.flowable.mapper.ProcessassignConfigMapper;
import com.thysdy.flowable.service.IProcessassignConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ML
 * @since 2020-09-11
 */
@Service
@Slf4j
public class ProcessassignConfigServiceImpl extends ServiceImpl<ProcessassignConfigMapper, ProcessassignConfig> implements IProcessassignConfigService {

    @Override
    public ProcessassignConfig getLatestProcessAssignConf(RequestVo requestVo) throws MyException {
        try {
            if (null != requestVo && null != requestVo.getProcessDefinitionKey()) {
                LambdaQueryWrapper<ProcessassignConfig> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(ProcessassignConfig::getDefinitionKey, requestVo.getProcessDefinitionKey());
                ProcessassignConfig config = getOne(queryWrapper);
                return config;
            } else {
                throw new MyException(CodeEnum.paramError);
            }
        } catch (MyException e) {
            throw e;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("getLatestProcessAssignConf error!", e);
            throw new MyException(CodeEnum.commonException);
        }
    }
}
